import MainAction from "./main";

export default class TreeAction{
    constructor(comp){
        this.comp = comp
        
    }

    onSelect =(key,e)=>{
        const {props,action} = this.comp
        const {main} = props
        if(key && key[0] !== '0-0'){
            let pk_itemtype = key && key[0]
            pk_itemtype = (pk_itemtype !== 'entryjob' && pk_itemtype !== 'leavejob') ? pk_itemtype.split('@')[0] :''
            let type = (e.node.props.pid || key && key[0])  === 'entryjob'  ? '1':'2'
            let title = (e.node.props.pid || key && key[0])  === 'entryjob' ? main.json['gx6008-000075']: main.json['gx6008-000076']
            props.button.setButtonDisabled({
                'add': pk_itemtype === ''? true:false,
            })
            props.dispatch({
                type: 'main/update',
                payload:{
                    pk_itemtype: pk_itemtype,
                    selectedKeys: key,
                    type: type,
                    title: title
                } 
            })
            action.tempAction.getTableData(pk_itemtype,type,main.pageInfo)
        }else{
            props.button.setButtonDisabled({
                'add': true,
                'delete': true
            })
            props.dispatch({
                type: 'main/update',
                payload:{
                    selectedKeys: key,
                } 
            })
            props.editTable.setTableData('handitemgrid',{rows:[]})
        }
        
    }

}